/*
 *   Copyright 2021 zzh
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */

package com.aduib.boot.common.disruptor;

import com.aduib.boot.common.lang.ObjectPool;

import java.io.Serializable;

/**
 * @description: Element
 * @author: zzh
 * @date: 2021/9/16 13:41
 */
public final class Elements<E> implements Serializable {

  private static final ObjectPool<Elements> RECYCLER =
          ObjectPool.newPool(handle -> new Elements(handle));

  private ObjectPool.Handle<Elements<E>> recyclerHandle;

  private long sequence;

  private E element;

  public Elements(ObjectPool.Handle<Elements<E>> handle) {
    this.recyclerHandle=handle;
  }

  public Elements() {

  }

  public Elements(long sequence) {
    this.sequence = sequence;
  }

  public Elements(long sequence, E element) {
    this.sequence = sequence;
    this.element = element;
  }

  static Elements newInstance() {
    return RECYCLER.get();
  }

  protected void recycle() {
    recyclerHandle.recycle(this);
  }

  public long getSequence() {
    return sequence;
  }

  public void setSequence(long sequence) {
    this.sequence = sequence;
  }

  public E getElement() {
    return element;
  }

  public void setElement(E element) {
    this.element = element;
  }
}
